﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class IntroScene : MonoBehaviour
{

    public List<GameObject> m_ListUnit;
    public bool m_bEmbark_Start;

    float m_fEmbarkTimer;
    bool m_bEmbark_OnceAtTime;

    int m_iUnitCounter;
	// Use this for initialization
	void Start () {
        m_fEmbarkTimer = 1.0f;
	}
	
	// Update is called once per frame
	void Update () {
        SkipCheck();
        Embark_Unit();
	}

    public void ToNextScene()
    {
        Application.LoadLevel(1);
    }

    void SkipCheck()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.LoadLevel(1);
        }
    }

    void Embark_Unit()
    {
        if (m_bEmbark_Start)
        {
            if (!m_bEmbark_OnceAtTime)
            {
                m_bEmbark_OnceAtTime = true;

                m_ListUnit[m_iUnitCounter].gameObject.SetActive(true);
                if (m_ListUnit.Count != m_iUnitCounter + 1)
                    m_iUnitCounter += 1;
                else
                {
                    m_bEmbark_Start = false;
                    GameObject.Find("IntroTruck").GetComponent<IntroTruck>().m_bAllEmbarked = true;
                }

            }
            else
            {
                m_fEmbarkTimer -= Time.deltaTime;

                if (m_fEmbarkTimer < 0)
                {
                    m_bEmbark_OnceAtTime = false;
                    m_fEmbarkTimer = 1.0f;
                }
            }
        }
    }
}
